package com.pine.app.module.security.oauth.plugin.intercept;

import com.pine.app.module.security.oauth.plugin.Plugin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.InitBinder;

import java.lang.reflect.Method;

/**
 * @author xiaoyuan
 * @create 2019/9/2 13:44
 **/


@Slf4j
public class PluginAspect extends StaticMethodMatcherPointcutAdvisor implements InitializingBean {


    private PluginInterceptor sysLogInterceptor;

    @Autowired
    public void setSysLogInterceptor(PluginInterceptor sysLogInterceptor) {
        this.sysLogInterceptor = sysLogInterceptor;
    }




    @Override
    public boolean matches(Method method, Class<?> aClass) {
        if ((method.getAnnotation(Plugin.class) != null) &&
                AnnotationUtils.findAnnotation(method, InitBinder.class) == null) {
            return true;
        }
        return false;
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        this.setAdvice(sysLogInterceptor);
    }
}
